package com.woniuxy.email.listener;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMailMessage;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 * @author yellow Docter
 * @date 2024-10-23
 * @desc 蜗牛创想：www.woniuxy.com
 */
@Component
public class EmailListener {

    @Autowired
    private JavaMailSender javaMailSender;

    @RabbitListener(queues = "email.queue")
    public void handler(Map<String,String> map){
        System.out.println("监听到消息："+map);

        //发邮件
        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject(map.get("subject"));
        message.setText(map.get("text"));
        message.setFrom(map.get("from"));
        message.setTo(map.get("to"));

        javaMailSender.send(message);

    }
}
